package pers.lx.crm.service.system.impl;

import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.lx.crm.base.common.pigeon.Result;
import pers.lx.crm.dao.system.SystemDao;
import pers.lx.crm.entiy.system.MenuDO;
import pers.lx.crm.service.system.SystemService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by lx on 2017/4/26.
 */
@Service
public class SystemServiceImpl implements SystemService{

    @Autowired
    private SystemDao systemDao ;

    @Override
    public Result getMenuList() {
        Result result = new Result() ;
        List<MenuDO> menuDOs = systemDao.selectMenus() ;
        HashMap<Integer,MenuDO> maps = new HashMap<Integer, MenuDO>() ;
        for(MenuDO menuDO:menuDOs){
            if(menuDO.getUp() == -1){
                maps.put(menuDO.getId(),menuDO) ;
                HashMap<String,String> menuDOmap = new HashMap<String, String>() ;
                result.addParam(menuDO.getName(),menuDOmap);
            }else {
                HashMap<String,String> menuDOmap = (HashMap<String,String>) result.getParamValue(maps.get(menuDO.getUp()).getName()) ;
                menuDOmap.put(menuDO.getName(),menuDO.getUrl()) ;
            }
        }
        return result;
    }
}
